/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Interfaz.java
 *
 * Created on 04-mar-2011, 14:55:25
 */

package interfaz;

import es.ucm.fdi.gaia.ontobridge.OntoBridge;
import es.ucm.fdi.gaia.ontobridge.OntologyDocument;
import es.ucm.fdi.gaia.ontobridge.test.gui.PnlSelectInstance;

import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JFileChooser;
import javax.swing.JTextArea;

public class Interfaz extends javax.swing.JFrame {

    private OntoBridge ob = new OntoBridge();
    public Interfaz() {
        inicializa();
        initComponents();
        Arbol();
        inicializaCombobox();
        inicializaComboboxConcepto();
        inicializaComboboxAcciones();
        inicializaEntidadesPerLug();
        inicializaPropAcci();
        foto="";
       
        this.setSize(980,800);
        this.setVisible(true);
    }

    private void inicializaPropAcci() {
		
    	 Iterator<String> itP = ob.listInstances("Persona");
         String s="";
         jComboBoxAccEntPer.removeAllItems();
         jComboBoxAccEntPer.addItem(s);
         while (itP.hasNext())
         {
        	 s=itP.next();
        	 s=ob.getShortName(s);
        	 jComboBoxAccEntPer.addItem(s);
         }
         Iterator<String> itE = ob.listInstances("Entidad");
         s="";
         while (itE.hasNext())
         {
        	 s=itE.next();
        	 s=ob.getShortName(s);
        	 jComboBoxAccEntPer.addItem(s);
         }
         Iterator<String> itAcc = ob.listInstances("Accion");
         s="";
         jComboBoxInstAcc.removeAllItems();
         jComboBoxInstAcc.addItem(s);
         while (itAcc.hasNext())
         {
        	 s=itAcc.next();
        	 s=ob.getShortName(s);
        	 jComboBoxInstAcc.addItem(s);
         }
         
	}

	private void inicializaComboboxAcciones() {
    	Iterator<String> itA = ob.listSubClasses("Accion", true);
    	
        String s="";
        jComboBoxAcciones.removeAllItems();
        while (itA.hasNext())
        {
       	 s=itA.next();
       	 s=ob.getShortName(s);
       	 jComboBoxAcciones.addItem(s);
       	 buscaSubclases(s,false);
        }
		
	}

	private void inicializaComboboxConcepto() {
    	Iterator<String> itP = ob.listAllClasses();
    	 String s="";
         jComboBoxConcepto.removeAllItems();
         while (itP.hasNext())
         {
        	 s=itP.next();
        	 //s=s.substring(53); //quitar URL ontologia
        	 s=ob.getShortName(s);
        	 if(!s.equals("owl:Nothing")){
        			 jComboBoxConcepto.addItem(s);
         	}
         }
	}

	private void buscaSubclases(String s,boolean lugar)
    {
    	Iterator<String> itP = ob.listSubClasses(s, true);
    	
    	if (!(itP.next().substring(30).equals("Nothing"))){ 
    		Iterator<String> itP1 = ob.listSubClasses(s, true);
    	while(itP1.hasNext())
    	{
    		String s2=itP1.next();
    		s2=s2.substring(53);
    		if (lugar) 
    			{
    				jComboBoxLugar.addItem(s2);
    				buscaSubclases(s2,true);
    			}sdfsfsdfsssssss
             
             dasfsdfasdfasdfsdfaasdf
             asdf
             asdf
             asdf
             asdf
    		
    		else
    		{
    			jComboBoxPerEnti.addItem(s2);
    			buscaSubclases(s2,false);
    		}
    		
    	}
    	}
    }

    private void inicializaEntidadesPerLug() {
    	Iterator<String> itP = ob.listSubClasses("Persona", true);
    	Iterator<String> itE = ob.listSubClasses("Entidad", true);
    	
        String s="";
        jComboBoxPerEnti.removeAllItems();
        jComboBoxPerEnti.addItem("Persona");
        while (itP.hasNext())
        {
       	 s=itP.next();
       	 s=s.substring(53); //quitar URL ontologia
       	 jComboBoxPerEnti.addItem(s);
       	 buscaSubclases(s,false);
        }
        
        String e="";
        while (itE.hasNext())
        {
       	 e=itE.next();
       	 e=e.substring(53); //quitar URL ontologia
       	 jComboBoxPerEnti.addItem(e);
       	 buscaSubclases(e,false);
        }
		
        Iterator<String> itL = ob.listSubClasses("Lugar", true);
        
        String l="";
        jComboBoxLugar.removeAllItems();
        while (itL.hasNext())
        {
       	 l=itL.next();
       	 l=l.substring(53); //quitar URL ontologia
       	 jComboBoxLugar.addItem(l);
       	 buscaSubclases(l,true);
        }
	}


	private void inicializaCombobox() {
    	 Iterator<String> itP = ob.listInstances("Persona"); 
         Iterator<String> itE = ob.listInstances("Entidad");
         String s="";
         jComboBoxAparece.removeAllItems();
         jComboBoxAparece.addItem(s);
         while (itP.hasNext())
         {
        	 s=itP.next();
        	 s=s.substring(53); //quitar URL ontologia
        	 jComboBoxAparece.addItem(s);
         }
         
         while (itE.hasNext())
         {
        	 s=itE.next();
        	 s=s.substring(53);//quitar URL ontologia
        	 jComboBoxAparece.addItem(s);
         }
         
         Iterator<String> itTL = ob.listInstances("Lugar");
         String l="";
         jComboBoxTieneLugar.removeAllItems();
         jComboBoxTieneLugar.addItem(l);
         while (itTL.hasNext())
         {
        	 l=itTL.next();
        	 l=l.substring(53);//quitar URL ontologia
        	 jComboBoxTieneLugar.addItem(l);
         }
         
		
         
	}


	private void inicializa() {



		ob.initWithPelletReasoner();

		OntologyDocument mainOnto = new OntologyDocument("http://www.owl-ontologies.com/Ontology1298640668.owl","file:Archivos/Practica4.owl");

		ArrayList<OntologyDocument> subOntologies = new ArrayList<OntologyDocument>();
		subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/calendar.owl","file:test/calendar.owl"));
		subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/price.owl","file:test/price.owl"));
		subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/address.owl","file:test/address.owl"));
		subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/contact-details.owl","file:test/contact-details.owl"));

		ob.loadOntology(mainOnto, subOntologies, false);



	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanelDerecho = new javax.swing.JPanel();
        jLabelIcono = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabelAccion = new javax.swing.JLabel();
        jLabelFecha  = new javax.swing.JLabel();
        jLabelConcepto  = new javax.swing.JLabel();
        jComboBoxAparece = new javax.swing.JComboBox();
        jComboBoxTieneLugar = new javax.swing.JComboBox();
        jComboBoxAcciones = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldAparece = new javax.swing.JTextField();
        jTextFieldTieneLugar = new javax.swing.JTextField();
        jTextFieldConcepto = new javax.swing.JTextField();
        jTextFieldFecha = new javax.swing.JTextField();
        jTextFieldAcciones = new javax.swing.JTextField();
        jButtonInstancia = new javax.swing.JButton();
        jButtonInstNueva = new javax.swing.JButton();
        jButtonAnadirElem = new javax.swing.JButton();
        jButtonAnadirConcepto = new javax.swing.JButton(); 
        jButtonAnadirPropAcc= new javax.swing.JButton(); 
        jMenuBar1 = new javax.swing.JMenuBar();
        
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItemConsultar = new javax.swing.JMenuItem();
        jMenuItemAbrir = new javax.swing.JMenuItem();
        jMenuItemGuardar = new javax.swing.JMenuItem();
        jComboBoxPerEnti= new javax.swing.JComboBox();
        jComboBoxLugar= new javax.swing.JComboBox() ;
        jComboBoxConcepto =  new javax.swing.JComboBox() ;
        jComboBoxAccEntPer =  new javax.swing.JComboBox() ;
        jComboBoxInstAcc =  new javax.swing.JComboBox() ;
        
        
        
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelIcono.setText("FOTO");

        jLabel2.setText("Aparece");

        jLabel3.setText("Tiene Lugar en");

        jLabel1.setText("Nueva instancia");
        
        jLabelFecha.setText("Fecha (AAAA-MM-DD)");
        
        jLabelConcepto.setText("Nuevo Concepto");
        
        jLabelAccion.setText("Realiza Accion");
        
        jTextFieldAcciones.setText("<<INSERTA UNA ACCION>>");
        jTextFieldAparece.setText("<<INSERTA UNA PERSONA O ENTIDAD>>");
        jTextFieldTieneLugar.setText("<<INSERTA UN LUGAR>>");
        
        jTextFieldAcciones.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextFieldAccionesMousePressed(evt);
            }
        
        });
        jTextFieldAparece.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextFieldAparaceMousePressed(evt);
            }
        
        });
        jTextFieldTieneLugar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextFieldLugarMousePressed(evt);
            }
        
        });
        jButtonInstancia.setText("Añadir Noticia");
        jButtonInstancia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonInstanciaActionPerformed(evt);
            }
        });

        jButtonInstNueva.setText("Aceptar Nueva Instancia");
        jButtonInstNueva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonInstNuevaActionPerformed(evt);
            }
        });
        jButtonAnadirElem.setVisible(false);
        jButtonAnadirElem.setText("Añade");
        jButtonAnadirElem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              anadirElemento();
            }

			
        });
        
        jButtonAnadirConcepto.setText("Añade Concepto");
        jButtonAnadirConcepto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              anadirConcepto();
            }

			
        });
        
        jButtonAnadirPropAcc.setText("Añade Propiedad realiza");
        jButtonAnadirPropAcc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
              anadirPropRealizaAccion();
            }

			
        });

        
        javax.swing.GroupLayout jPanelDerechoLayout = new javax.swing.GroupLayout(jPanelDerecho);
        jPanelDerecho.setLayout(jPanelDerechoLayout);
        jPanelDerechoLayout.setHorizontalGroup(
            jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
            .addGroup(jPanelDerechoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDerechoLayout.createSequentialGroup()
                        .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelIcono, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelDerechoLayout.createSequentialGroup()
                                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabelFecha)//////////////
                                    .addComponent(jButtonInstancia)
                                    .addComponent(jLabelConcepto)
                                    .addComponent(jButtonAnadirConcepto)
                                    .addComponent(jComboBoxAccEntPer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(39, 39, 39)
                                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxAparece, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBoxTieneLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldFecha, javax.swing.GroupLayout.DEFAULT_SIZE, 80,80)//////////////
                                    .addComponent(jButtonAnadirElem)
                                    .addComponent(jComboBoxConcepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelAccion))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldTieneLugar)
                                    .addComponent(jTextFieldAparece, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                                    .addComponent(jTextFieldAcciones, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                                    .addComponent(jButtonInstNueva)
                                    .addComponent(jTextFieldConcepto, javax.swing.GroupLayout.DEFAULT_SIZE, 80,80)
                                    .addComponent(jComboBoxInstAcc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        		.addComponent(jComboBoxPerEnti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        		.addComponent(jComboBoxLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        		.addComponent(jComboBoxAcciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        		 .addComponent(jButtonAnadirPropAcc))
                        .addGap(60, 60, 60))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelDerechoLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(125, 125, 125))))
            .addGroup(jPanelDerechoLayout.createSequentialGroup()
                .addGap(45, 45, 45)
                //.addComponent(jButtonInstancia)
                .addGap(150, 150, 150)
                //.addComponent(jButtonInstNueva)
                .addContainerGap(104, Short.MAX_VALUE))
        );
        jPanelDerechoLayout.setVerticalGroup(
            jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDerechoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelIcono, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBoxAparece, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldAparece, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxPerEnti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBoxTieneLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldTieneLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
               .addGap(18, 18, 18)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelFecha)//////////////////////////
                    .addComponent(jTextFieldFecha,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldAcciones,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxAcciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonInstancia)
                    .addComponent(jButtonAnadirElem)
                    .addComponent(jButtonInstNueva))
                .addContainerGap(22, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelConcepto)
                    .addComponent(jComboBoxConcepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldConcepto,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jButtonAnadirConcepto))
                .addContainerGap(22, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanelDerechoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxAccEntPer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelAccion)
                    .addComponent(jComboBoxInstAcc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAnadirPropAcc))
                .addContainerGap(22, Short.MAX_VALUE)
                )
        );

        jSplitPane1.setRightComponent(jPanelDerecho);

        jMenu1.setText("Archivo");
        jMenu2.setText("Consulta");
        
        jMenuItemAbrir.setText("Abrir Foto");
        jMenu1.add(jMenuItemAbrir);
        jMenuItemAbrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAbrirActionPerformed(evt);
            }

			
        });
        

        jMenuItemConsultar.setText("realizar Consulta");
        jMenu2.add(jMenuItemConsultar);
        jMenuItemConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	realizarConsulta();
            }

			
        });
        
        
        jMenuItemGuardar.setText("Guardar Ontologia");
        jMenu1.add(jMenuItemGuardar);
        jMenuItemGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	ob.save("Archivos/Practica4.owl");
            }

			
        });
        jMenuBar1.add(jMenu1);
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE)//javax.swing.GroupLayout.Alignment.TRAILING
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            //.addGroup(layout.createSequentialGroup()//javax.swing.GroupLayout.Alignment.TRAILING,javax.swing.GroupLayout.PREFERRED_SIZE
            	.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, javax.swing.GroupLayout.PREFERRED_SIZE)
                //.addContainerGap(19, Short.MAX_VALUE)
                
        );

        pack();
    }
    
    private void realizarConsulta() {
		InterfazConsulta interConsul=new InterfazConsulta();
		this.setVisible(false);
		interConsul.setVisible(true);
		interConsul.setInter(this);
		
	}
    public OntoBridge getONTO(){
    	return ob;
    }

	private void jTextFieldAccionesMousePressed(java.awt.event.MouseEvent evt) {
       jTextFieldAcciones.setText("");
    }
    private void jTextFieldAparaceMousePressed(java.awt.event.MouseEvent evt) {
        jTextFieldAparece.setText("");
     }
    private void jTextFieldLugarMousePressed(java.awt.event.MouseEvent evt) {
        jTextFieldTieneLugar.setText("");
     }
    private void anadirConcepto(){
    	String s=(String)jComboBoxConcepto.getSelectedItem();
    	String con=jTextFieldConcepto.getText();
    	if(!con.equals("")){
    		ob.createClass(con);
    		ob.setSubClass(con, s);
    	}
    	
    }
    
    private void  anadirPropRealizaAccion(){
    	String s=(String)jComboBoxAccEntPer.getSelectedItem();
    	String s2=(String)jComboBoxInstAcc.getSelectedItem();
    	if(!s.equals("")&&(!s.equals(""))){
    		ob.createOntProperty(s, "realiza",s2 );
    	}
    }
    
    
    private void jButtonInstanciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInstanciaActionPerformed
    	if(!foto.equals("")){
	    	
	       String nombre=/*"Noticia_"+*/dameNombreNoticia(foto);
	        String apar=jComboBoxAparece.getSelectedItem().toString();
	        
	       
	        if(!ob.existsInstance(nombre, "Noticia")){
	        	ob.createInstance("Noticia", nombre);
	        }
	        if(!apar.equals("")){
	        	ob.createOntProperty(nombre, "aparece",apar );
	        }
	        ob.createDataTypeProperty(nombre, "url_foto", "img\\"+nombre); ////MODIFICAMOS para obtener nuestra ruta
	       
	        String lugar=jComboBoxTieneLugar.getSelectedItem().toString();
	        if(!lugar.equals("")){
	        	ob.createOntProperty(nombre, "tieneLugar",lugar );
	        }
	        String fec=jTextFieldFecha.getText();
	        if(!fec.equals("")){
	        	ob.createDataTypeProperty(nombre, "fecha", fec,
	        			"http://www.w3.org/2001/XMLSchema#date");
	        }
    	}
    	
    }

    private void jButtonInstNuevaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInstNuevaActionPerformed
      String aparece = jTextFieldAparece.getText();
      if(!aparece.equals("") && !aparece.equals("<<INSERTA UNA PERSONA O ENTIDAD>>")) 
      {
    	  if (!ob.existsInstance(aparece))
    	  {
    		  ob.createInstance((String)jComboBoxPerEnti.getSelectedItem(), aparece);
    	  }
    	  
      }
      
      String tl = jTextFieldTieneLugar.getText();
      if(!tl.equals("") && !tl.equals("<<INSERTA UN LUGAR>>")) 
      {
    	  if (!ob.existsInstance(tl))
    	  {
    		  ob.createInstance((String)jComboBoxLugar.getSelectedItem(), tl);
    	  }
    	  
      }
      String a = jTextFieldAcciones.getText();
      if(!a.equals("") && !a.equals("<<INSERTA UNA ACCION>>")) 
      {
    	  if (!ob.existsInstance(a))
    	  {
    		  ob.createInstance((String)jComboBoxAcciones.getSelectedItem(), a);
    	  }
      }
      
      inicializaCombobox();
      inicializaComboboxConcepto();
      inicializaComboboxAcciones();
      inicializaEntidadesPerLug();
      inicializaPropAcci();

            
    }
    private void jMenuItemAbrirActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		JFileChooser jFil=new JFileChooser();
		int seleccion=jFil.showOpenDialog(new JTextArea());
		if (seleccion == JFileChooser.APPROVE_OPTION)
		{
			File f=jFil.getSelectedFile();
			 foto=f.toString();
			jLabelIcono.setText("");
			jLabelIcono.setIcon(new javax.swing.ImageIcon(FileIO.findFile(foto)));
		}
		
		
	}
    
    private void anadirElemento() {
		
		
	}
    //////MIRARLO 
   private String dameNombreNoticia(String f){
	   int i=f.length();
	   String salida="";
	   while(f.charAt(i-1)!='\\'){
		   	salida=f.charAt(i-1)+salida;
	   		i--;
   		}
   		return salida;
   }
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interfaz().setVisible(true);
            }
        });
    }
    private void Arbol(){
            PnlSelectInstance tree = new PnlSelectInstance(ob);
			jSplitPane1.setLeftComponent(tree);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonInstNueva;
    private javax.swing.JButton jButtonInstancia;
    private javax.swing.JButton jButtonAnadirElem;
    private javax.swing.JButton jButtonAnadirConcepto;
    private javax.swing.JButton jButtonAnadirPropAcc;
    private javax.swing.JComboBox jComboBoxAparece;
    private javax.swing.JComboBox jComboBoxTieneLugar;
    private javax.swing.JComboBox jComboBoxPerEnti;
    private javax.swing.JComboBox jComboBoxLugar;
    private javax.swing.JComboBox jComboBoxConcepto;
    private javax.swing.JComboBox jComboBoxAcciones;
    private javax.swing.JComboBox jComboBoxAccEntPer;
    private javax.swing.JComboBox jComboBoxInstAcc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelIcono;
    private javax.swing.JLabel jLabelFecha;
    private javax.swing.JLabel jLabelConcepto;
    private javax.swing.JLabel jLabelAccion;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuItemConsultar;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItemAbrir;
    private javax.swing.JMenuItem jMenuItemGuardar;
    private javax.swing.JPanel jPanelDerecho;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTextField jTextFieldAparece;
    private javax.swing.JTextField jTextFieldTieneLugar;
    private javax.swing.JTextField jTextFieldFecha;
    private javax.swing.JTextField jTextFieldConcepto;
    private javax.swing.JTextField jTextFieldAcciones;
    private String foto;
    // End of variables declaration//GEN-END:variables

}
